<template>
  <div id="major">
    <div id="title">注册</div>
    <div id="division"></div>
    <div id="input">
      <el-form :model="dynamicValidateForm" ref="dynamicValidateForm" class="demo-dynamic">
        <el-form-item prop="email" :rules="[
            { required: true, message: '请输入邮箱地址', trigger: 'blur' },
            {
              type: 'email',
              message: '请输入正确的邮箱地址',
              trigger: ['blur', 'change'],
            },
          ]"
        >
          <el-input v-model="dynamicValidateForm.email" placeholder="请输入邮箱"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" class="demo-ruleForm">
      <div id="input">
        <el-form-item prop="pass">
          <el-input type="password" v-model="ruleForm.pass" autocomplete="off" placeholder="请输入密码"></el-input>
        </el-form-item>
      </div>
      <div id="input">
        <el-form-item prop="checkPass">
          <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off" placeholder="请再次输入密码"></el-input>
        </el-form-item>
      </div>
    </el-form>
        <router-link to="/login"><div id="login">返回登录</div></router-link>

    <button @click="register()">注册</button>
  </div>
</template>
<script>
import { Register } from "@/service/Api.js";
export default {
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.ruleForm.checkPass !== "") {
          this.$refs.ruleForm.validateField("checkPass");
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.ruleForm.pass) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      dynamicValidateForm: {
        email: "",
      },
      ruleForm: {
        pass: "",
        checkPass: "",
      },
      rules: {
        pass: [{ validator: validatePass, trigger: "blur" }],
        checkPass: [{ validator: validatePass2, trigger: "blur" }],
      },
    };
  },
  methods: {
    register() {
      let params = {
        email: this.dynamicValidateForm.email,
        password: this.ruleForm.pass,
        password_confirmation: this.ruleForm.checkPass,
        name: "222",
      };
      Register(params).then((res) => {
        console.log(res);
        this.$router.push("/login");
      });
    },
  },
};
</script>
<style scoped>
#login{
  font-size: 12px;
  color: #ccc;

  width: 87%;
  margin: auto;
  margin-top: 16px;

}

body {
  background-color: #fff;
}

button :focus {
  opacity: 0.5;
}

.input /deep/ .el-input__inner {
  transition: border-width 0.2s ease-out;
}
#input {
  width: 87%;
  margin: auto;
  margin-top: 32px;
}
.el-input :focus {
  border-left-width: 20px;
}
.el-input {
  transition: border-width 0.2s ease-out;
}
#division {
  background: #ccc;
  height: 0.5px;
  width: 87%;
  margin: auto;
}
#title {
  font-size: 1.2em;
  color: #444;
  font-weight: bold;
  width: 87%;
  margin: auto;
  margin-top: 18px;
  margin-bottom: 12px;
}

#handle {
  width: 87%;
  margin: auto;
  margin-top: 32px;
}
#pass {
  font-size: 12px;
  color: #ccc;
  float: left;
}
#register {
  font-size: 12px;
  color: #ccc;
  float: right;
}
@media screen and (min-width: 980px) {
  #major {
    position: absolute;
    left: 0;
    right: 0;
    margin-left: auto;
    margin-right: auto; /*绝对定位方法*/
    width: 320px;
    height: 400px;
    background-color: #fff;
    margin-top: 180px;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.12), 0 0 2px rgba(0, 0, 0, 0.04);
  }
  button {
    cursor: pointer;
    outline: none;
    color: #fff;
    font-size: 17px;
    font-weight: 200;
    text-align: center;
    line-height: 60px;
    background: #2196f3;
    border: 0px solid rgba(0, 0, 0, 0.1);
    border-radius: 0px;
    position: absolute;
    left: 0;
    bottom: 0;
    max-height: 60px;
    width: 100%;
    height: 60px;
  }
}
@media screen and (max-width: 980px) {
  body {
    background-color: #fff;
  }
  #major {
    width: 100%;
    height: 550px;
    background-color: #fff;
  }
  button {
    cursor: pointer;
    outline: none;
    color: #fff;
    font-size: 17px;
    font-weight: 200;
    text-align: center;
    line-height: 60px;
    background: #2196f3;
    border: 0px solid rgba(0, 0, 0, 0.1);
    border-radius: 0px;
    position: fixed;
    left: 0;
    bottom: 0;
    max-height: 60px;
    width: 100%;
    height: 60px;
  }
  * {
    background-color: #fff;
  }
}
</style>